package org.cupk2.base.event;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.cupk2.base.domain.CupkUserContext;
import org.cupk2.base.domain.CupkUserContextLoader;
import org.cupk2.base.event.enums.F2EActionT;
import org.cupk2.tools.time.CupkTimeTool;

/**
 * 定义事件行为
 */
@Data
@NoArgsConstructor
public class F2EAction {
    private F2EActionT type;
    private F2EUser operator;
    private String time;

    public F2EAction(F2EActionT cupk2EventActionType) {
        CupkUserContext user = CupkUserContextLoader.getCurrentUser();
        this.init(cupk2EventActionType, user);
    }


    public F2EAction(F2EActionT cupk2EventActionType, CupkUserContext user) {
        this.init(cupk2EventActionType, user);
    }


    private void init(F2EActionT cupk2EventActionType, CupkUserContext user) {
        if (user != null) {
            this.operator = new F2EUser();
            this.operator.setUserKey(user.getLoginname());
            this.operator.setIp(user.getIp());
        } else {
            this.operator = F2EUser.getAnonymous();
        }
        this.type = cupk2EventActionType;
        this.time = CupkTimeTool.getTimeDate14();
    }

}
